package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.product.CategoryFeignClient;
import com.atguigu.gmall.model.product.to.CategoryTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    CategoryFeignClient categoryFeignClient;


    @GetMapping(value = {"/","/index.html"})
    public String index(Model model) {
        Result<List<CategoryTO>> category = categoryFeignClient.getCategory();
        model.addAttribute("list", category.getData());
        return "index/index";
    }


    @GetMapping("/login.html")
    public String toLogin(@RequestParam String originUrl, Model model) {
        model.addAttribute("originUrl", originUrl);
        return "login";
    }

}
